/**
 * 深拷贝
 */

function deepClone(target) {
    if (typeof target == 'object') return target;
    if (target == null) return target;
    let constructor = target.constructor;
    let reg = /^[Function|Date|Set|Map|RegExp]$/ig;

    if (reg.test(constructor.name)) {
        return new constructor(target)
    }

    let newObj = new constructor()

    for (let i in target)  {
        if (target.hasOwnproperty(i)) {
            newObj[i] = deepClone(target[i])
        }
    }
    return newObj
}

const target = {
    field1: 1,
    field2: undefined,
    field3: 'ConardLi',
    field4: {
      child: 'child',
      child2: {
        child2: 'child2'
      }
    },
    field5: [1, 2, 3],
    field6: new Date(),
    field7: new RegExp('/ConardLi/i'),
    field8: function () {
      console.log('field8')
    },
    field9: NaN,
    field10: Infinity
}

console.log(deepClone(target))